$(function () {
    $("#jqGrid").jqGrid({
        url:baseURL+"sys/bank/list" ,
        datatype: "json",
        colModel: [
            { label: '信用卡id', name: 'bankId', width: 80,align:'center' , sortable: false},
            { label: '合伙人姓名', name: 'name', width: 80, align:'center' , sortable: false},
            { label: '合伙人手机', name: 'phone', width: 45,align:'center' , sortable: false},
            { label: '银行名称', name: 'bankName', width: 120,align:'center'},
            { label: '卡号', name: 'bankNo', width:120,align:'center' , sortable: false},
            { label: '户主姓名', name: 'cardName', width: 45,align:'center'},
            { label: '激活时间', name: 'createDate', width:75, formatter:function(value, options, row){
                    return value==null?"-":value;},align:'center' , sortable: false},
            { label: '是否默认', name: 'isDefault', width: 60,align:'center',formatter:function (value,options,row) {
                    return value==1?"是":"否";
                } , sortable: false},
            { label: '是否显示', name: 'isShow', width: 50,align:'center',formatter:function (value,options,row) {
                    return value==1?"是":"否";
                } , sortable: false},


        ],
		viewrecords: true,
        height: 375,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect:true,
        multiboxonly:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });


});





var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            name:null,
            phone:null
        },
        showList: true,
        showUpdate:false,
        title:null,
        bank:{
            bankId:null,
            bankName:null,
            bankNo:null,
            cardName:null
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        clean: function () {
            vm.showList = true;
            vm.q = {
                name: null,
                phone: null,
            };
            $("#jqGrid").jqGrid('setGridParam', {page: 1});
            vm.reload();
        },
        update: function () {
            var rowid=getSelectedRow();
            var row = $("#jqGrid").jqGrid('getRowData', rowid);
            if(rowid==null){
                return;
            }
            let bankId=row.bankId;
            console.log(bankId);
            vm.showList = false;
            vm.showUpdate = true;
            vm.title = "修改";

            $.get(baseURL+"sys/bank/queryById/"+bankId,result=>{
                vm.bank=result.bank;
            })
        },
        modify: function () {
            $.ajax({
                url: baseURL + "sys/bank/updateBank",
                type: "post",
                contentType: "application/json",
                data: JSON.stringify(vm.bank),
                success: function (r) {
                    if (r.code == 0) {
                        alert(r.msg);
                        vm.reload();
                    } else {
                        alert(r.msg)
                    }
                }
            })
        },
        reload: function () {
            vm.showList = true;
            vm.showUpdate = false;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'name': vm.q.name,
                    'phone': vm.q.phone
                },
                page: page
            }).trigger("reloadGrid");

        }



    }
});
